<?php
/**
 * @purpose: 对“请求”类型中子类型为2(加好友)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_request_type2_encoder() {
	return " "; //todo: 接口提供方支持字串""的赋值后，将此处改为""
}

function msg_request_type2_decoder() {
	$fields = array("id","senderid","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}


	$users_infos = UCModUserInfo::getUserInfos(array($senderid, $receiverid), array(USERINFO_NICKNAME,USERINFO_AVATAR_90,USERINFO_INTERESTS,USERINFO_FAV_BOOKS,USERINFO_FAV_MOVIES));

	$seduser_nickname = htmlspecialchars($users_infos[$senderid][USERINFO_NICKNAME]);
	$seduser_nickname == '' && $seduser_nickname = $senderid;

	$sender_url = get_user_home_url($senderid);
	$sender     = "<a href=\"{$sender_url}\" target='_blank'>{$seduser_nickname}</a>";

	if ($fmt == 'line') {
		return sprintf("%s 加你为好友，你也加Ta为好友吧！", $sender); #输出处，不做html转义


	} else if ($fmt == 'box') {
		$receiver_avatar_url = $users_infos[$receiverid][USERINFO_AVATAR_90];
		$time                = time_formater($createTime);

		$attri = $users_infos[$senderid];
		!is_array($attri) && $attri = array();
		$attri = array_map("htmlspecialchars", $attri);



		#####sender stats,  gogogo   ####
		// -- for count(fans)
		require_once dirname(__FILE__)."/../../../models/relation/UCModRelation.php";
		$o_relation   = new UCModRelation($senderid);
		$n_friends    = (int)$o_relation->getRelationFollowCount();
		// -- for count(twitter)
		require_once dirname(__FILE__)."/../../../models/user/UCModUserStatistics.php";
		$o_user_stats = new UCModUserStatistics($senderid);
		$n_twitter    = (int)$o_user_stats->getValue(UC_STAT_MOOD_CNT);
		// -- for count(medal)
		$n_medals     = (int)$o_user_stats->getValue(UC_STAT_MODAL_CNT);
		// -- for count(leave_msg)
		require_once dirname(__FILE__)."/../../../models/comment/UCModComment.php";
		$o_comment    = new UCModComment();
		$n_comments   = (int)$o_comment->amountComment('home',md5($senderid),'module',$senderid);
		// -- 资料完成度
		$seduser      = UCModUserInfo::getUser($senderid);
		$n_completed  = $seduser->getCompletePercent()."%";
		#####sender stats,  ends     ####



		$html = <<<HTML
<div class="emailUserList">
	<img src="{$receiver_avatar_url}" class="avatar-45" />
	<img src="{$attri[USERINFO_AVATAR_90]}" class="avatar-45" />
	<div class="clear"></div>
</div>
<div class="emailQues">
	<div class="emailKey">{$sender} 加你为好友，你也加Ta为好友吧！</div>
	<div class="userInfo">
		<div class="avatarImg"><a href="{$sender_url}" target="_blank"><img src="{$attri[USERINFO_AVATAR_90]}"></a></div>
		<div class="userDetails">
			<h3 class="game"><span class="r">{$time}</span>{$sender}</h3>
			<a href="javascript:;" class="addFriBtnSmall" id="req_add_fri_{$id}" data="{$senderid}|{$seduser_nickname}"></a><a href="javascript:;" class="txt1" id="req_ignore_{$id}">忽略</a>
		</div>
		<div class="clear"></div>
	</div>
	<div class="avatarNum">
		<ul>
			<li><a href="/index.php/home/badge/home/{$senderid}" target="_blank"><span><b>{$n_medals}</b><br />勋章</span></a></li>
			<li><a href="/index.php/home/friends/home/{$senderid}" target="_blank"><span><b>{$n_friends}</b><br />好友</span></a></li>
			<li><a href="/index.php/home/tuita/home/{$senderid}" target="_blank"><span><b>{$n_twitter}</b><br />推他</span></a></li>
			<li><a href="/index.php/home/message/home/{$senderid}" target="_blank"><span><b>{$n_comments}</b><br />留言</span></a></li>
			<li class="none"><a href="/index.php/home/data/home/{$senderid}" target="_blank"><span><b>{$n_completed}</b><br />资料</span></a></li>
			<div class="clear"></div>
		</ul>
	</div>
	<h2 class="pd10">个人档案</h2>
	<dl class="infoList">
		<dt>兴趣爱好：</dt>
		<dd>{$attri[USERINFO_INTERESTS]}</dd>
		<dt>喜欢的书：</dt>
		<dd>{$attri[USERINFO_FAV_BOOKS]}</dd>
		<dt>喜欢的电影：</dt>
		<dd>{$attri[USERINFO_FAV_MOVIES]}</dd>
	</dl>
	<!--
	<h2 class="pd10">最近玩的应用</h2>
	<div class="app playApp">
		<a href="#"><img src="../images/app/app1.png" /><br />推他</a>
		<a href="#"><img src="../images/app/app2.png" /><br />勋章馆</a>
		<a href="#"><img src="../images/app/app3.png" /><br />信箱</a>
		<a href="#"><img src="../images/app/app4.png" /><br />酷六视频</a>
		<a href="#"><img src="../images/app/app5.png" /><br />推他</a>
		<div class="clear"></div>
	</div>-->
</div>
HTML;

		return $html;


	} else {
		return "";
	}

}


